package com.polaris.live.popup

import android.content.Context
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.adapter.chatPrice.SetPriceAdapter
import com.polaris.live.common.R
import com.polaris.live.common.databinding.PopupSetPriceBinding
import com.polaris.live.common.ext.toLevel
import com.polaris.live.dialog.GlobalDialogManager
import com.polaris.live.resp.back_resp.UserCallPriceBaseVo
import com.polaris.live.translation.R.string

/**
 * 设置价格弹窗
 *
 * @author Created by 长空 on 2023/11/08/004 13:52
 */
class SetPricePopup(
    context: Context,
    private val price: Long,
    private val level: Long,
    private val minLevel: Long,
    private val priceList: List<UserCallPriceBaseVo>,
    private val priceCallBack: ((price: Long) -> Unit),
) : BottomPopupView(context) {

    private lateinit var mBinding: PopupSetPriceBinding

    private val mAdapter by lazy { SetPriceAdapter() }

    override fun getImplLayoutId(): Int {
        return R.layout.popup_set_price
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupSetPriceBinding.bind(popupImplView)

        mBinding.recyclerView.adapter = mAdapter

        mAdapter.setOnItemClickListener { adapter, view, position ->
            if (level < minLevel) {
                GlobalDialogManager.showCommonDialog(
                    context,
                    "${StringUtils.getString(string.me_chat_price_tip)}${
                        StringUtils.getString(
                            string.me_chat_price_tip_level, minLevel.toLevel
                        )
                    }",
                    onConfirmListener = {
                    })
                return@setOnItemClickListener
            }
            priceCallBack.invoke(mAdapter.data[position].price)
            dismiss()
        }

        mAdapter.setUserPrice(price)
        mAdapter.setList(priceList)

    }

}